package com.woniu.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.commons.exception.YogaException;
import com.woniu.commons.model.Result;
import com.woniu.commons.util.JwtUtil;
import com.woniu.commons.util.RedisUtil;
import com.woniu.model.dto.LeagueClassDetailDto;
import com.woniu.model.form.AddLeagueClassDetailForm;
import com.woniu.model.form.PageForm;
import com.woniu.model.model.YGoodsOrder;
import com.woniu.model.model.YLeagueClassDetail;
import com.woniu.model.param.PageParam;
import com.woniu.service.YLeagueClassDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 胡歌
 * @since 2024年05月28日
 */
@RestController
@RequestMapping("/yLeagueClassDetail")
@Api(tags = "团课课程详细跟踪接口")
public class YLeagueClassDetailController {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private YLeagueClassDetailService leagueClassDetailService;

    /**
     * 新增团课详细跟踪
     * @param form
     * @return
     * @throws YogaException
     */
    @PostMapping("/addLeagueClassDetail")
    @ApiOperation(value = "新增团课详细跟踪")
    public Result addLeagueClassDetail(@RequestBody AddLeagueClassDetailForm form) throws YogaException {

        leagueClassDetailService.addLeagueClassDetail(form);
        return Result.getResult().setMsg("新增成功");
    }

    /**
     * 完成团课详细
     * @param leagueClassWorkforceId
     * @return
     * @throws YogaException
     */
    @GetMapping("/finishLeagueClassDetail")
    @ApiOperation(value = "完成团课详细")
    public Result finishLeagueClassDetail(Integer leagueClassWorkforceId) throws YogaException {

        leagueClassDetailService.finishLeagueClassDetail(leagueClassWorkforceId);
        return Result.getResult().setMsg("完成当堂课成功");
    }

    /**
     * 取消团课详细
     * @param leagueClassWorkforceId
     * @return
     */
    @GetMapping("/cancelLeagueClassDetail")
    @ApiOperation(value = "取消团课详细")
    Result<?> cancelLeagueClassDetail( Integer leagueClassWorkforceId){
        leagueClassDetailService.cancelLeagueClassDetail(leagueClassWorkforceId);
        return Result.getResult().setMsg("取消团课详情成功");
    }

//    /**
//     * 教练遍历自己的团课
//     * @param leagueClassWorkforceId
//     * @return
//     */
//    @GetMapping("/loadLeagueClassDetailByCoach")
//    @ApiOperation(value = "教练遍历自己的团课")
//    Result<?> loadLeagueClassDetailByCoach( Integer leagueClassWorkforceId){
//        leagueClassDetailService.cancelLeagueClassDetail(leagueClassWorkforceId);
//        return Result.getResult().setMsg("取消团课详情成功");
//    }

    /**
     * 用户遍历自己的团课
     * @param classState 单堂课程状态
     * @param token
     * @return
     */
    @GetMapping("/loadLeagueClassDetailByUser")
    @ApiOperation(value = "用户遍历自己的团课")
    Result<List<LeagueClassDetailDto>> loadLeagueClassDetailByUser(@RequestHeader String token, Integer classState,String leagueClassName){
        String s = redisUtil.get(token);
        Integer userId = Integer.parseInt(JwtUtil.parseToken(s).get("userId").toString());

        List<LeagueClassDetailDto> list = leagueClassDetailService.loadLeagueClassDetailByUser(userId,classState,leagueClassName);

        return Result.newListInstance(LeagueClassDetailDto.class).setMsg("查询团课详情成功");
    }

}

